package map;

import objects.Enemy;
import tools.Coordinate;

public class CollisionDetector {

	private static CollisionDetector collisionDetector;

	public static CollisionDetector getInstance() {
		if (collisionDetector == null) {
			collisionDetector = new CollisionDetector();
		}
		return collisionDetector;
	}

	private CollisionDetector() {
	};

	public boolean isAccessible(Level level, Coordinate coord) {

		boolean result = false;

		if (coord.getX() >= 0 && coord.getX() < level.getTiles().length
				&& coord.getY() >= 0
				&& coord.getY() < level.getTiles()[0].length) {
			if (level.getTiles()[coord.getX()][coord.getY()] != null) {
				if (level.getTiles()[coord.getX()][coord.getY()].isAccessible()) {
					result = true;
				}
			}

		}
		return result;
	}

	public boolean isEnemyAtPos(Level level, Coordinate coord) {
		boolean result = false;

		for (Enemy enemy : level.getListEnemies()) {
			if (enemy.getxPosition() == coord.getX()
					&& enemy.getyPosition() == coord.getY()) {
				result = true;
			}
		}

		return result;
	}

}
